package com.jinlejia.erp.ui.new_house.adapter;


import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.freedom.yefeng.yfrecyclerview.YfListAdapter;
import com.freedom.yefeng.yfrecyclerview.YfSimpleViewHolder;
import com.jinlejia.erp.R;

import java.util.ArrayList;
import java.util.Map;

/**
 * 列表下拉adapter
 */

public class ListViewDownAdapter extends YfListAdapter<Map<String, Object>> {

    private Context context;

    public ListViewDownAdapter(Context context ,ArrayList<Map<String, Object>> data) {
        super(data);
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateDataViewHolder(ViewGroup parent) {
        context = parent.getContext().getApplicationContext();
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_down_layout,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public RecyclerView.ViewHolder onCreateEmptyViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.empty_layout, parent, false);
        TextView txt = (TextView) view.findViewById(R.id.id_tips);
        txt.setText("暂无数据");
        return new YfSimpleViewHolder(view);
    }

    @Override
    public void onBindDataViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ((ViewHolder)holder).title.setText(mData.get(position).get("title").toString());
        ((ViewHolder)holder).content.setText(mData.get(position).get("remark").toString());
        holder.itemView.setTag(mData.get(position));
    }

    @Override
    public RecyclerView.ViewHolder onCreateLoadingViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.loading_layout, parent, false);
        return new YfSimpleViewHolder(view);
    }

    @Override
    public RecyclerView.ViewHolder onCreateFooterViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_foot_layout, parent, false);
        return new footViewHolder(view);
    }

    @Override
    public void onBindFooterViewHolder(RecyclerView.ViewHolder holder, int position) {
        super.onBindFooterViewHolder(holder, position);
        ((footViewHolder)holder).title.setText(mFooters.get(0).toString());
        if (mFooters.get(position).toString().equals("收起")){
            ((footViewHolder)holder).icon.setImageResource(R.mipmap.ic_drop_down_yellow);
        }else {
            ((footViewHolder)holder).icon.setImageResource(R.mipmap.ic_drop_down_yellow);
        }
    }
    private static final class footViewHolder extends RecyclerView.ViewHolder {

        TextView title;
        ImageView icon;
        public footViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.title);
            icon = (ImageView) itemView.findViewById(R.id.image_flage);
        }
    }


    private static final class ViewHolder extends RecyclerView.ViewHolder {

        TextView title;
        TextView content;

        public ViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.title);
            content = (TextView) itemView.findViewById(R.id.content);

        }

    }
}
